import yagmail

def send_mail(to_email, subject, contents):
    try:
        # 使用yagmail发送邮件，确保正确处理中文
        yag = yagmail.SMTP(
            user="99@yirc.ntesmail.com",
            password="ur7wDjfGQQkEhHa5",
            host="hwsmtp.qiye.163.com",
            port=465,
            encoding='utf-8'  # 显式指定UTF-8编码
        )
        # 发送邮件，确保所有内容都是Unicode字符串
        yag.send(
            to=to_email,
            subject=subject,
            contents=contents
        )
        print(f"邮件发送成功，接收者: {to_email}")
        return True
    except Exception as e:
        print(f"邮件发送失败: {str(e)}")
        return False
